let app = getApp()
Component({ 
    properties: {
         pagetitle:String,
         styleType: {
          type: String,
          observer: function(newVal, oldVal) {
            this.updateRate()
          }
        }
      },
      data:{
        couponStatus: [ {
          title: "未使用",
          id: 0
      }, {
          title: "已使用",
          id: 1
      }, {
          title: "已过期",
          id: 2
      } ],
      list: [],
      couponStatusCur: 0,
      status:0,
      page:1,
      },
    lifetimes: {
        attached: function () {
          this.get_data();
       } 
      },
    methods: {
      updateRate:function(){
        this.get_data();
      },
      get_data:function(){
        var that=this
        if(that.data.styleType=='style2'){
          wx.request({
            url: app.globalData.siteroot,
            data: {
              do:'Shop_getCouponList',
              page:that.data.page,
              user_id:wx.getStorageSync('user_id')
            },
            success: function(res) {
              that.setData({
                list:res.data.data,
                params:'style2'
              })
            }
          })
        }else{
          wx.request({
            url: app.globalData.siteroot,
            data: {
              do:'Shop_getUserCouponList',
              status:that.data.status,
              page:that.data.page,
              user_id:wx.getStorageSync('user_id')
            },
            success: function(res) {
              that.setData({
                params:'private',
                list:res.data.data,
                page:that.data.page+1
              })
            }
          })
        }
      },
      changestatus:function(e){
        this.setData({
          page:1,
          status:e.detail.cur
        })
        this.get_data();
      },
      scrollToLower: function(e) {
        var that=this
        if(this.data.styleType!='style2'){
          wx.request({
            url: app.globalData.siteroot,
            data: {
              do:'Shop_getUserCouponList',
              status:that.data.status,
              page:that.data.page,
              user_id:wx.getStorageSync('user_id')
            },
            success: function(res) {
              if(res.data.data.length>0){
                that.setData({
                  list:that.data.list.concat(res.data.data),
                  page:that.data.page+1
                })
              }else{
                wx.showToast({
                  title:res.data.msg,
                  icon: 'none',
                  duration: 1500
                })
              }
            }
          })
        }
      }
    }
});
